public class StringConcatenate {
    public static void main(String args[]) {
        long startTime = System.currentTimeMillis();
        for (int i = 0; i < 50000; i++) {
            String result = "This is"+"testing the"+"Difference"+"between"+"String"+"and"+"StringBuffer";
        }
        long endTime = System.currentTimeMillis();
        System.out.println("通过String类连接字符串" + ":" + (endTime - startTime) + "毫秒");
        long startTime1 = System.currentTimeMillis();
        for (int i = 0; i < 50000; i++) {
            StringBuffer result = new StringBuffer("This is");
            result.append("testing the");
            result.append("Difference");
            result.append("between");
            result.append("String");
            result.append("and");
            result.append("StringBuffer");
        }
        long endTime1 = System.currentTimeMillis();
        System.out.println("字符串连接" + " - 使用 StringBuffer : " + (endTime1 - startTime1)+ " ms");
    }
}
